/*
 * StatusInfo.java
 *
 * Created on 27 Август 2010 г., 11:13
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.jimm.protocol;

import org.jimm.app.R;

import android.util.Log;

/**
 * @author Vladimir Kryukov
 */
public final class StatusInfo {
    private static final String LOG_TAG = "Jimm:protocol.StatusInfo";
    public static final byte STATUS_OFFLINE = 0;
    public static final byte STATUS_ONLINE = 1;
    public static final byte STATUS_AWAY = 2;
    public static final byte STATUS_CHAT = 3;

    public static final int PSTATUS_ALL = 0;
    public static final int PSTATUS_VISIBLE_ONLY = 1;
    public static final int PSTATUS_NOT_INVISIBLE = 2;
    public static final int PSTATUS_CL_ONLY = 3;
    public static final int PSTATUS_NONE = 4;

    // Jabber statuses
    public static final int STATUS_XA = 9;//4;
    public static final int STATUS_DND = 11;//5;
    // Mrim statuses
    public static final int STATUS_UNDETERMINATED = 10;//4;
    public static final int STATUS_INVISIBLE = 12;//5;
    // Icq statuses
    public static final int STATUS_NA = 9;
    public static final int STATUS_OCCUPIED = 10;
    public static final int STATUS_INVIS_ALL = 13;

    public static final int STATUS_EVIL = 6;
    public static final int STATUS_DEPRESSION = 7;

    public static final int STATUS_HOME = 4;
    public static final int STATUS_WORK = 5;
    public static final int STATUS_LUNCH = 8;

    public static final int STATUS_NOT_IN_LIST = 14;
    public static final int STATUS_CONNECTING = 15;

    public static Integer[] statusIcons;

    public static Integer[] globalStatusIcons = {
            R.drawable.ic_status_offline,
            R.drawable.ic_status_online,
            R.drawable.ic_status_away,
            R.drawable.ic_status_ffc,
            R.drawable.icq_status_home,
            R.drawable.icq_status_work,
            R.drawable.icq_status_evil,
            R.drawable.icq_status_depression,
            R.drawable.icq_status_lunch,
            R.drawable.ic_status_na,
            R.drawable.ic_status_occupied,
            R.drawable.ic_status_dnd,
            R.drawable.ic_status_invisible,
            R.drawable.ic_status_invisible,
            R.drawable.ic_status_invisible,
            R.drawable.ic_status_connecting,
    };
    public static final Integer[] statusNames = {
            R.string.status_offline,
            R.string.status_online,
            R.string.status_away,
            R.string.status_chat,
            R.string.status_home,
            R.string.status_work,
            R.string.status_evil,
            R.string.status_depression,
            R.string.status_lunch,
            R.string.status_na,
            R.string.status_occupied,
            R.string.status_dnd,
            R.string.status_invisible,
            R.string.status_invis_all,
    };
    public static final Integer[] privateStatusIcons = {
            R.drawable.ic_private_status_visible_to_all,
            R.drawable.ic_private_status_visible_to_white_list,
            R.drawable.ic_private_status_visible_to_all_exclude_black_list,
            R.drawable.ic_private_status_visible_to_contacts_only,
            R.drawable.ic_private_status_invisible_for_all
    };
    public static final Integer[] privateStatusNames = {
            R.string.private_status_visible_to_all,
            R.string.private_status_visible_to_white_list,
            R.string.private_status_visible_to_all_exclude_black_list,
            R.string.private_status_visible_to_contacts_only,
            R.string.private_status_invisible_for_all
    };


    /**
     * Creates a new instance of StatusInfo
     */
    public StatusInfo(Integer[] statuses) {
        statusIcons = statuses;
    }

    public int getName(int statusIndex) {
        if (statusIndex == STATUS_NOT_IN_LIST)
            return R.string.status_not_in_list;

        if (statusIndex == STATUS_CONNECTING)
            return R.string.status_connecting;

        return statusNames[statusIndex];
    }

    public int getIcon(int statusIndex) {
        if (statusIndex > statusIcons.length || statusIndex < 0) {
            Log.e(LOG_TAG, "bad statusIndex");
            return 0;
        }// else if  (statusIndex == STATUS_CONNECTING)
        //	return R.string.status_connecting;
        else
            return statusIcons[statusIndex];
    }

    public static int getGlobalStatusIcon(int statusIndex) {
        if (statusIndex > globalStatusIcons.length || statusIndex < 0) {
            Log.e(LOG_TAG, "bad statusIndex");
            return 0;
        }// else if  (statusIndex == STATUS_CONNECTING)
        //	return R.string.status_connecting;
        else
            return globalStatusIcons[statusIndex];
    }

    public final boolean isAway(int statusIndex) {
        switch (statusIndex) {
            case StatusInfo.STATUS_OFFLINE:
            case StatusInfo.STATUS_AWAY:
            case StatusInfo.STATUS_DND:
            case StatusInfo.STATUS_XA:
            case StatusInfo.STATUS_UNDETERMINATED:
            case StatusInfo.STATUS_INVISIBLE:
            case StatusInfo.STATUS_INVIS_ALL:
            case StatusInfo.STATUS_NOT_IN_LIST:
                return true;
        }
        return false;
    }

    private static final int[] statusWidth = {29, 1, 7, 0, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 14};

    public static int getWidth(int status) {
        return statusWidth[status];
    }
}
